rm(list=ls())
library(foreign)
dat <- read.csv("Directory/UCDP_Termination_Dataset_2015") ## Download your own dataset from https://ucdp.uu.se/ 

###### Number of Rebel Groups #####
require(data.table)

numreb <- matrix(ncol=2, nrow=length(unique(dat$ConflictId)))

group <- unique(dat$ConflictId)

for(i in 1:length(unique(dat$ConflictId))){
  numreb[i,1] <- group[i]
  newdat <- subset(dat, ConflictId==group[i])
  numreb[i,2] <- length(unique(newdat$SideB))
}

colnames(numreb) <- c( "conflictid", "numreb")
numreb <- as.data.frame(numreb)

write.dta(numreb, "numreb3.dta")


View(numreb)

# End of File